// 5. 号码生肖规范规则
// 生肖顺序为鼠>牛>虎>兔>龙>蛇>马>羊>猴>鸡>狗>猪。
// 如今年是兔年，就以兔为开始，依顺序将49个号码分为12个生肖如下
// 鼠：04 16 28 40
// 牛：03 15 27 39
// 虎：02 14 26 38
// 兔：01 13 25 37 49
// 龙：12 24 36 48
// 蛇：11 23 35 47
// 马：10 22 34 46
// 羊：09 21 33 45
// 猴：08 20 32 44
// 鸡：07 19 31 43
// 狗：06 18 30 42
// 猪：05 17 29 41

// 计算今年的年份
const currentYear = new Date().getFullYear()

// 计算生肖的年份起始值（兔年对应的是4）
const shengxiaoStartYear = 4

// 计算今年的生肖年份
const shengxiaoIndex = (currentYear - shengxiaoStartYear) % 12 //3

const animal = [
  { name: '鼠', nums: [], word: 'mouse', playCode: "SHU" },
  { name: '牛', nums: [], word: 'cow', playCode: "NIU" },
  { name: '虎', nums: [], word: 'tiger', playCode: "HU" },
  { name: '兔', nums: [], word: 'rabbit', playCode: "TU" },
  { name: '龙', nums: [], word: 'dragon', playCode: "LONG" },
  { name: '蛇', nums: [], word: 'snake', playCode: "SHE" },
  { name: '马', nums: [], word: 'horse', playCode: "MA" },
  { name: '羊', nums: [], word: 'sheep', playCode: "YANG" },
  { name: '猴', nums: [], word: 'monkey', playCode: "HOU" },
  { name: '鸡', nums: [], word: 'chicken', playCode: "JI" },
  { name: '狗', nums: [], word: 'dog', playCode: "GOU" },
  { name: '猪', nums: [], word: 'pig', playCode: "ZHU" },
];

let maxLeng = animal.length

// 初始化每个生肖第1个数字，
for (let i = 0; i < animal.length; i++) {
  if (i < shengxiaoIndex) {
    animal[i].nums.push(shengxiaoIndex - i + 1)
  } else if (i === shengxiaoIndex) {
    animal[i].nums.push(1)
  } else {
    animal[i].nums.push(maxLeng)
    maxLeng--
  }
}

// 生肖数组第1个数据+12 就是第2个数字的值
for (let key in animal) {
  for (let i = 0; i < 3; i++) {
    let lastEl = animal[key].nums[animal[key].nums.length - 1]
    animal[key].nums.push(lastEl + 12)
  }
}

// 今年的年份会多个49
animal[shengxiaoStartYear-1].nums.push(49)

let animalMap = {}
animal.forEach((item) => {
  item.nums.forEach((number, index) => {
    let num = number.toString().padStart(2, '0')
    item.nums.splice(index, 1, num)
    animalMap[num] = item.name
  })
})

const animalList = animal
export { animalList, animalMap }
